<%@page import="pojo.*,java.util.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<script type="text/javascript">
	// kiểm tra giỏ có trống hay không -> cho đặt hàng

	function KiemTraGioHang() {

		if (document.getElementById('thongTinSanPham') != null) {
			
			
			/*String
			tenNguoiNhan = document.getElementById('txtTenNguoiNhan').value;
			String
			diaChiNguoiNhan = document.getElementById('txtDiaChiNguoiNhan').value;
			String
			soDienThoai = document.getElementById('txtSoDienThoai').value;
			
			window.location.href = 'TrangGioHang.do?action=DatHang'
					+ '&tenNguoiNhan=' + tenNguoiNhan + '&diaChiNguoiNhan='
					+ diaChiNguoiNhan + '&soDienThoai=' + soDienThoai;
			*/
			String
			diaChiNguoiNhan = document.getElementById('txtDiaChiNguoiNhan').value;
			window.location.href = 'TrangHoaDon.do?action=DatHang'
				+'&diaChiNguoiNhan='+ diaChiNguoiNhan;
		} else
			alert("Không có sản phẩm trong giỏ hàng!");
	}
</script>

<div id="ContentPanel">
	<!-- Content -->
	<div id="MainPanel" align="left">

		<form name="gioHang" action="TrangGioHang.do" method="post">
			<div class="ContentPart">
				<h3 class="ContentPartHeader">THÔNG TIN GIỎ HÀNG</h3>
				<!-- <form name="gioHang" action="TrangGioHang.do" method="post"> -->
				<table class="tableDulieu">
					<tr align="center">
						<th width="6%"><strong>STT</strong></th>
						<th><strong>TÊN SẢN PHẨM</strong></th>
						<th width="15%"><strong>SỐ LƯỢNG</strong></th>
						<th width="15%"><strong>GIÁ BÁN</strong></th>
						<th width="15%"><strong>THÀNH TIỀN</strong></th>
						<th width="6%"><strong>XÓA</strong></th>
					</tr>

					<!-- DemoJSTL -->



					<c:set var="tongTien" value="0" />

					<c:if
						test="${null != sessionScope.gioHang && sessionScope.gioHang.size() > 0}">
						<!-------------						
						<c:forEach var="sp" items="${sessionScope.gioHang}">
						</c:forEach>
						---------------->
						<c:forEach var="i" begin="0"
							end="${sessionScope.gioHang.size()-1}">
							<tr id="thongTinSanPham" valign="top">
								<td align="center">${i + 1}</td>
								<td><a href="#">${sessionScope.gioHang[i].getTensanpham()}</a></td>
								<td width="12%"><label for="soLuong"></label> <input
									name="soLuong" type="text" id="soLuong"
									value="${sessionScope.gioHang[i].getSoluongtronggiohang()}"
									size="17" /></td>
								<td align="right"><fmt:formatNumber type="number"
										value="${sessionScope.gioHang[i].getGiaban()}" /></td>
								<td align="right"><fmt:formatNumber type="number"
										value="${sessionScope.gioHang[i].getGiaban() *
									sessionScope.gioHang[i].getSoluongtronggiohang()}"
										groupingUsed="true" /></td>
								<td align="center"><a
									href="TrangGioHang.do?action=Xoa&maSP=${sessionScope.gioHang[i].getMasanpham()}">
										<img src="../Images/Icon/icon_delete.png" alt="Xóa" border="0" />
								</a></td>
							</tr>
							<c:set var="tongTien"
								value="${tongTien + sessionScope.gioHang[i].getGiaban() *
									sessionScope.gioHang[i].getSoluongtronggiohang()}" />
						</c:forEach>
					</c:if>

					<tr valign="top">
						<td colspan="4" align="right">Tổng thành tiền</td>
						<td colspan="2" align="center"><strong><font
								color="#FF0000"> <fmt:formatNumber type="number"
										value="${tongTien}" groupingUsed="true" /> VNÐ
							</font></strong></td>
					</tr>
				</table>
				<!-- </form> -->
			</div>
			<div class="ContentPart">
				<h3 class="ContentPartHeader">THÔNG TIN NGƯỜI ĐẶT HÀNG</h3>
				<div class="ContentPartContent">
					<div class="ins">Tên người đặt:</div>
					<div class="info" id="tenNguoiDat">
						${sessionScope.taiKhoan.getHoten()}</div>
					<div class="ins">Email:</div>
					<div class="info" id="email">${sessionScope.taiKhoan.getEmail()}</div>
					<div class="ins">Địa chỉ:</div>
					<div class="info" id="diaChi">${sessionScope.taiKhoan.getDiachi()}</div>

				</div>
			</div>
			<div class="ContentPart">
				<h3 class="ContentPartHeader">THÔNG TIN NGƯỜI NHẬN HÀNG</h3>
				<div class="ContentPartContent">
					<!-- <div class="ins">Tên người nhận:</div>
					<input class="txtField" type="text" id="txtTenNguoiNhan" size=auto
						value="Nguyễn Quốc Nhã" /> <br />
						-->
					<div class="ins">Địa chỉ người nhận:</div>
					<input class="txtField" type="text" id="txtDiaChiNguoiNhan"
						size=auto value="212/25 Đoàn Văn Bơ, P10, Quận 4" /> <br />
					<!-- 
					<div class="ins">Số điện thoại:</div>
					<input class="txtField" type="text" id="txtSoDienThoai" size=auto
						value="01234567890" />
						 -->
				</div>
			</div>
			<br />
			<div class="ContentPart" align="right">
				<a class="buttonLink" href="TrangGioHang.do?action=TiepTucMua">
					<div class="button">Tiếp tục mua</div>
				</a> <input type="submit" name="btCapNhat" class="button buttonLink"
					value="Cập Nhật"></input><input type="hidden" name="action"
					value="CapNhat" />
				<!-- <a class="buttonLink" href="TrangGioHang.do?action=CapNhat">
					<div class="button">Cập Nhật</div>
				</a>  -->
				<a class="buttonLink">
					<div class="button" onclick="KiemTraGioHang()">Đặt hàng</div>
				</a> <a class="buttonLink"
					href="TrangGioHang.do?action=ThemVaoGio&maSP=1101365">
					<div class="button">Thêm SP</div>
				</a>
			</div>
		</form>
	</div>

	<!-- Content -->
</div>